package net.tomred.example;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public class VersionInfo {

    /**
     * @param args
     */
    public static void main(String[] args) {
//	try {
//	    System.out.println("MANIFEST.MF ===");
//	    Enumeration<URL> resources = VersionInfo.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
//	    while (resources.hasMoreElements()) {
//		Manifest manifest = new Manifest(resources.nextElement().openStream());
//		String builtby = manifest.getMainAttributes().getValue("Built-By");
//		if (builtby != null && builtby.equals("tomred.net")) {
//		    Attributes tomredatts = manifest.getAttributes("tomred.net");
//		    for (Object key : tomredatts.keySet()) {
//			System.out.println(key + " : " + tomredatts.get(key));
//		    }
//		}
//	    }
//	    System.out.println("MANIFEST.MF ===");
//	} catch (IOException E) {
//	}
	
	try {
	    System.out.println("MANIFEST.MF ===");
	    Enumeration resources = VersionInfo.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
	    while (resources.hasMoreElements()) {
		URL resource = (URL)resources.nextElement();
		Manifest manifest = new Manifest(resource.openStream());
		String builtby = manifest.getMainAttributes().getValue("Built-By");
		if (builtby != null && builtby.equals("tomred.net")) {
		    Attributes tomredatts = manifest.getAttributes("tomred.net");
		    Set keys = tomredatts.keySet();
		    Iterator it = keys.iterator();
		    while(it.hasNext()){
			Object key = it.next();
			System.out.println(key + " : " + tomredatts.get(key));
		    }
		}
	    }
	    System.out.println("MANIFEST.MF ===");
	} catch (IOException E) {
	}
    }

}
